package com.example.cloudpracticeplatform.service.impl;

import com.example.cloudpracticeplatform.entity.Student;
import com.example.cloudpracticeplatform.mapper.StudentMapper;
import com.example.cloudpracticeplatform.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public int register(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public Student login(String username, String password) {
        Student student = studentMapper.findByUsername(username);
        if (student != null && student.getPassword().equals(password)) {
            return student;
        }
        return null;
    }

    @Override
    public int update(Student student) {
        return studentMapper.update(student);
    }

    @Override
    public int delete(Integer studentId) {
        return studentMapper.delete(studentId);
    }

    @Override
    public Student findById(Integer studentId) {
        return studentMapper.findById(studentId);
    }

    @Override
    public List<Student> getStudents(int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return studentMapper.findAll(offset, pageSize);
    }
}